package com.seeyon.kk.utils;


import java.util.HashMap;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.kk.manager.BaseManager;




public class CaigouStopUtils extends BaseManager{
	
	
	public static String getToken() throws Exception {
		// 创建一个get请求对像，url为该请求的地址
		HttpClient httpClient = new HttpClient();
		// token地址（ll:rest登录名 ， 123456:rest密码）
		//http://52.80.120.70
		//http://uc.locknlock.com.cn
		String url = "http://uc.locknlock.com.cn/seeyon/rest/token/lockuser/lockuser123";
		GetMethod method = new GetMethod(url);
		method.addRequestHeader("content-type", "application/json");
		// 执行该get请求并获取返回的HTTP状态码
		httpClient.executeMethod(method);
		// 获取该请求成功处理后的页面返回内容
		String responses = method.getResponseBodyAsString();
		// 获取的信息转json
		System.out.println(responses);
		//JSONObject json = JSONObject.parseObject(responses);
		// 获取id的值
		 
		String token = (String) responses;
		return token;

	}
	/**
	 * @添加部门
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("deprecation")
	public static String getDept(Map<String, Object> map) throws Exception {
		// 创建一个post请求对像，url为该请求的地址
		HttpClient httpClient = new HttpClient();
		String url = "http://uc.locknlock.com.cn/seeyon/rest/affair/stop";
		PostMethod post = new PostMethod(url);

		Map<String, Object> dept = new HashMap<String, Object>();
		dept.put("affairId", MapUtils.getString(map, "AFFRIAID")); //affairId
		dept.put("repealComment", "");// 编号
		dept.put("member",MapUtils.getString(map, "LOGIN_NAME"));//名称

		String json2 = JSONObject.toJSONString(dept);
		post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
		//post.addRequestHeader("responses", getToken());
		post.addRequestHeader("token", getToken());
		post.setRequestBody(json2);
		post.addRequestHeader("content-type", "application/json");
		// 执行该post请求并获取返回的HTTP状态码
		httpClient.executeMethod(post);
		// 获取该请求成功处理后的页面返回内容
		String add = new String(post.getResponseBody(), "utf-8");
		System.out.println(add);
		return add;
	}

}
